package Windows;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JToolBar;

import Tools.IMG;
import Windows.ShowWindows.ShowWindow;
import WindowsModule.Yonghuzhuce;
import XML.XMLNode;

/**
 * 主界面工具栏
 * 
 * @author Administrator
 * 
 */
public class ResToolBar extends JToolBar {
	public final JButton jbLogin = new JButton();
	public final JButton jbReg = new JButton();
	public final JButton jbNewTask = new JButton();
	public final JButton jbSeach = new JButton();
	public final JButton jbCloseSearch = new JButton();// 关闭搜索表格
	public final JButton jbSharePath = new JButton();
	public final JButton jbUpdateShare = new JButton();
	public final JButton jbUp = new JButton();

	private BufferedImage bi;

	public ResToolBar() {

		jbLogin.setActionCommand("toolbar_开始");

		jbLogin.setIcon(IMG.TBlogin);
		jbReg.setIcon(IMG.TBreg);
		jbNewTask.setIcon(IMG.TBnew);
		jbSeach.setIcon(IMG.TBsearch);
		jbCloseSearch.setIcon(IMG.TBClose);
		jbSharePath.setIcon(IMG.TBshare);
		jbUpdateShare.setIcon(IMG.TBSHAREUPDATE);
		jbUp.setIcon(IMG.TBup);

//		File file = new File("Skin/close.png");
//		try {
//			bi = ImageIO.read(file);
//			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 32, 32));
//			jbCloseSearch.setIcon(img);
//		} catch (IOException e) {
//		}
//
//		file = new File("Skin/play.png");
//		try {
//			bi = ImageIO.read(file);
//			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 32, 37));
//			jbStart.setIcon(img);
//		} catch (IOException e) {
//		}
//
//		file = new File("Skin/stop.png");
//		try {
//			bi = ImageIO.read(file);
//			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 32, 37));
//			jbStop.setIcon(img);
//		} catch (IOException e) {
//		}
//		file = new File("Skin/hips32.png");
//		try {
//			bi = ImageIO.read(file);
//			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 32, 32));
//			jbNewTask.setIcon(img);
//		} catch (IOException e) {
//		}
////		file = new File("Skin/danger32.png");
////		try {
////			bi = ImageIO.read(file);
////			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 32, 32));
////			jButton5.setIcon(img);
////		} catch (IOException e) {
////		}
//		file = new File("Skin/seachs.png");
//		try {
//			bi = ImageIO.read(file);
//			ImageIcon img = new ImageIcon(bi.getSubimage(0, 0, 37, 37));
//			jbSeach.setIcon(img);
//		} catch (IOException e) {
//		}
		this.setBorder(null);
		this.setRollover(true);

		jbLogin.setToolTipText("用户登陆");
		jbReg.setToolTipText("免费注册");
		jbNewTask.setToolTipText("新建任务");
		jbSeach.setToolTipText("高级搜索");
		jbUp.setToolTipText("向上");
		jbSharePath.setToolTipText("设置共享目录");
		jbUpdateShare.setToolTipText("刷新共享目录");
		jbCloseSearch.setToolTipText("关闭搜索窗口");

		jbLogin.setBorderPainted(false);// 不会绘制边框
		jbLogin.invalidate();// 使其无效
		jbReg.setBorderPainted(false);// 不会绘制边框
		jbReg.invalidate();// 使其无效
		jbNewTask.setBorderPainted(false);// 不会绘制边框
		jbNewTask.invalidate();// 使其无效
		jbSeach.setBorderPainted(false);// 不会绘制边框
		jbSeach.invalidate();// 使其无效
		jbCloseSearch.setBorderPainted(false);// 不会绘制边框
		jbCloseSearch.invalidate();// 使其无效
		jbUp.setBorderPainted(false);// 不会绘制边框
		jbUp.invalidate();// 使其无效
		jbSharePath.setBorderPainted(false);// 不会绘制边框
		jbSharePath.invalidate();// 使其无效
		jbUpdateShare.setBorderPainted(false);// 不会绘制边框
		jbUpdateShare.invalidate();

		jbLogin.setFocusable(false);
		jbLogin.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbLogin.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbLogin.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				ShowWindow.DisplayWindow(MainWindows.loginWindows, 1);
			}
		});
		this.add(jbLogin);

		jbReg.setFocusable(false);
		jbReg.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbReg.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbReg.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				ShowWindow.DisplayWindow(new Yonghuzhuce(), 3);
			}
		});
		this.add(jbReg);

		jbNewTask.setFocusable(false);
		jbNewTask.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbNewTask.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbNewTask.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				MainWindows.ndf.setNewTask(new XMLNode(null, "File"), true);

			}
		});
		this.add(jbNewTask);

		jbSeach.setFocusable(false);
		jbSeach.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbSeach.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbSeach.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				MainWindows.csw.setVisible(true);
				ShowWindow.PalyWindow(MainWindows.csw);
			}
		});
		this.add(jbSeach);

		jbSharePath.setFocusable(false);
		jbSharePath.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbSharePath.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbSharePath.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainWindows.spow.jTextField1.setText(MainWindows.getInstance().client.sp.getF().getAbsolutePath());
				ShowWindow.DisplayWindow(MainWindows.spow, 1);

			}
		});
		this.add(jbSharePath);

		jbUpdateShare.setFocusable(false);
		jbUpdateShare.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbUpdateShare.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbUpdateShare.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainWindows.getInstance().client.sp.setAlter(true);
			}
		});

		this.add(jbUpdateShare);

		jbUp.setFocusable(false);
		jbUp.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbUp.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		jbUp.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				MainWindows.getInstance().mpanel.getResp().up();
			}
		});
		this.add(jbUp);

		jbCloseSearch.setFocusable(false);
		jbCloseSearch.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
		jbCloseSearch.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
		this.add(jbCloseSearch);

	}
}
